package com.shanzmoo.admin.web.sys;


import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.core.cache.CurrentUserCache;
import com.shanzmoo.db.sys.entity.dto.*;
import com.shanzmoo.db.sys.entity.vo.OutletInfoPageVo;
import com.shanzmoo.db.sys.entity.vo.OutletInfoSelectVo;
import com.shanzmoo.db.sys.service.IOutletInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 门店信息 前端控制器
 * </p>
 *
 * @author Gzhao
 * @since 2020-12-09
 */

@Api(tags = "系统-门店信息")
@RestController
@RequestMapping("/sys/outlet")
public class OutletInfoController {

    @Autowired
    private IOutletInfoService outletInfoService;

    @ApiOperation(value = "添加")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody OutletInfoSaveDto saveDto) {
        SResponse<Boolean> re = outletInfoService.add(saveDto, CurrentUserCache.getUserId());
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "删除")
    @GetMapping("/delete")
    public SHttpResponse<Boolean> deleteById(@RequestParam(value = "outletId") Integer outletId) {
        SResponse<Boolean> re = outletInfoService.deleteById(outletId, CurrentUserCache.getUserId());
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "修改")
    @PostMapping("/update")
    public SHttpResponse<Boolean> update(@Valid @RequestBody OutletInfoUpdateDto updateDto) {
        SResponse<Boolean> re = outletInfoService.edit(updateDto, CurrentUserCache.getUserId());
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<OutletInfoPageVo>> pageList(@Valid @RequestBody OutletInfoQueryDto queryDto) {
        SResponse<PageRespBase<OutletInfoPageVo>> re = outletInfoService.getPageList(queryDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "门店选择列表")
    @GetMapping("/selectList")
    public SHttpResponse<List<OutletInfoSelectVo>> selectList() {
        List<OutletInfoSelectVo> re = outletInfoService.selectList(CurrentUserCache.getOutletId());
        return SHttpResponse.ok(re);
    }

}
